# -*- coding:utf-8 -*-
class EncryptFile:
    def __init__(self, key, mark):
        self._key = key
        self._mark = mark

    def encrypt(self, input, output):
        f_read = open(input, "rb")
        f_write = open(output, "wb")
        f_write.write(bytes(self._mark.encode(encoding='utf-8')))

        count = 0

        for now in f_read:
            for nowByte in now:
                newByte = nowByte ^ ord(self._key[count % len(self._key)])
                count += 1
                f_write.write(bytes([newByte]))

        f_read.close()
        f_write.close()

    def decrypt(self, input, output):
        f_read = open(input, "rb")
        f_write = open(output, "wb")

        f_read.seek(len(self._mark))
        count = 0

        for now in f_read:
            for nowByte in now:
                newByte = nowByte ^ ord(self._key[count % len(self._key)])
                count += 1
                f_write.write(bytes([newByte]))

        f_read.close()
        f_write.close()


# key = "xof@!sdk"
# mark = "Encrypted_1.0"
# path = "/Users/zhangjing/project/xinghe/wqds/client/build/jsb-default/assets/HallView/native/1a"
# hepler = EncryptFile(key, mark)
# hepler.encrypt(
#     path+'/1a2d71151.d4856.png', path+'/加密.png')
# hepler.decrypt(path+'/加密.png', path+'/解密.png')
